﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
judge(int n, int arr[3][3])
{
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (arr[i][j] != 0)
				return 0;
		}
	}
	return 1;
}
int main()
{
	int n = 0;
	scanf("%d", &n);
	int arr[3][3] = { 0 };
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
			scanf("%d", &arr[i][j]);
	}
	int ret = judge(n, arr);
	if (0 == ret)
		printf("NO\n");
	if (1 == ret)
		printf("YES\n");

	return 0;
}